define([
  'apiClient', 'moment', 'template7compile'
], function(apiClient, moment, template7compile) {
  var self = {};

  function dataAnalysis(data) {
    return {
      lecturer: {
        id: data.lecturerId,
        name: data.lecturerName
      },
      assistant: {
        id: data.assistantId,
        name: data.assistantName
      },
      course: {
        id: data.courseId,
        className: data.courseClass,
        classroom: data.classroomName,
        time: moment(data.startTime, moment.ISO_8601).format('H:mm') + '-' + moment(data.endTime, moment.ISO_8601).format('H:mm'),
        introduces: [],
      }
    };
  }

  self.init = function(e) {
    // tabbar swith
    $$('.tab-link').on('click', function() {
      $$('.tab-link').removeClass('active');
      $$(this).addClass('active');
      $$('.tab-link').each(function() {
        if ($$(this).hasClass('active')) {
          $$(this).children('i').addClass('active');
        } else {
          $$(this).children('i').removeClass('active');
        }
      })
    });
    // down arrow cell scale
    $$('.scaleable').on('click', function() {
      $$(this).children('p').toggleClass('display-none');
      $$(this).children('.arrow').toggleClass('img-arrow-up');
      $$(this).children('.arrow').toggleClass('img-arrow-down');
    });
    // course note page skip
    $$('.course-note').on('click', function() {
      mainView.router.load({
        url: '<%= purl ' teacher_side / course / note ' %>',
        query: {}
      })
    });
    // related people
    $$('.related-person').on('click', function() {
      mainView.router.load({
        url: '<%= purl ' teacher_side / course / related - person ' %>',
        query: {}
      })
    });
    //  template preload
    var courseId = e.detail.page.query.courseId;
    apiClient.get('/teacher/courseFields/detail.do', {
      id: courseId
    }, function(data, status, xhr) {
      if (status.toString() == '200') {
          // T.B.D.
        //   template7compile.compile('#course-detail ', dataAnalysis(data.data), '')

      }
    }, function(xhr, status) {})
  }
  self.afterAnime = function() {
    // tabbar select initialize
    $$('.course-detail').click();
  }
  return self;
})
